<template>
	<div class="app-container">
		<el-tabs type="card" @tab-click="handleClick" v-model="activeName">
			<el-tab-pane label="最终结果" name="first" v-loading="loading">
				<IndexAssessForm />
			</el-tab-pane>
			<el-tab-pane label="中间结果" name="second">
				<el-table v-loading="middleResultloading" :data="middleResultList">				
					<el-table-column label="生成时间" align="center" prop="createTime" />
					<el-table-column label="生成人" align="center" prop="createUserName" />
					<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
		        <template #default="scope">
		        	<el-button type="text" @click="handleEdit(scope.row)">修改</el-button>
		        	<el-button type="text" @click="handleReplace(scope.row)">替换为最终结果</el-button>
		          <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>	          
		        </template>
      		</el-table-column>
				</el-table>

				 <pagination v-show="total>0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows" @pagination="getList" /> 
			</el-tab-pane>
		</el-tabs>
	</div>
</template>

<script setup name="indexAssess">
	import { getDzzhTaskModel, replaceFinalResult, deleteCenter } from "@/api/weakSoilAssess/indexAssess";
	import IndexAssessForm from './indexAssessForm.vue'
	
	const route = useRoute();
	const router = useRouter();
	const { proxy } = getCurrentInstance();
	const activeName = ref("first");
	const middleResultList = ref([]);
	const slopeVersion = ref("0");
	const loading = ref(false);
	const middleResultloading = ref(true);
	const total = ref(0);


	const data = reactive({
		queryParams: {
			page: 1,
			rows: 10,
		}
	});

	const { queryParams } = toRefs(data);

	/** 删除按钮操作 */
	function handleDelete(row) {
		
		proxy.$modal.confirm('是否确认删除？').then(function() {			
		}).then(() => {
			
			deleteCenter({"taskId":row.taskId,"versionCode":slopeVersion.value,"dtcvId":row.dtcvId}).then(response => {
				console.log(response.data);	
				proxy.$modal.msgSuccess("删除成功");
				getList();
			});
			
		}).catch(() => {});
	}
	//获取中间结果列表
	function getList(){
		middleResultloading.value = true;
		getDzzhTaskModel({...queryParams.value,"taskId":route.query.taskId}).then(response => {
			middleResultloading.value = false;
			console.log(response.data)	
			middleResultList.value = response.data.rows;
			total.value = response.data.total;

		});
	}
	//修改
	function handleEdit(row){
		router.push({
			path: "/rtAnalysisAssess/indexAssessForm",
			query: {
				...route.query,
				metaTitle: `修改${route.query.metaTitle}中间结果`,
				dtcvId: row.dtcvId
			}
		})
	}
	//替换为最终结果
	function handleReplace(row){
		var taskId = row.taskId;
		proxy.$confirm('请选择是否将被替换的结果存为中间结果选择“否”，被替换的结果作废','系统提示',
		{confirmButtonText: '是',cancelButtonText: '否',type: 'warning'}).then(function() {
		}).then(() => {
			replaceFinalResult({"versionCode":slopeVersion.value,"yes":"1","taskId":taskId,"dtcvId":row.dtcvId}).then(response => {			
				console.log(response.data)
				proxy.$modal.msgSuccess(response.data);
				getList();
			});
		}).catch(() => {
			replaceFinalResult({"versionCode":slopeVersion.value,"yes":"0","taskId":taskId,"dtcvId":row.dtcvId}).then(response => {			
				console.log(response.data)
				proxy.$modal.msgSuccess(response.data);
				getList();
			});
		});
	}
	//切换标签页
	function handleClick(tab, event) {
		if(tab.props.name == 'second') {
			getList()
		}
	}
</script>
<style scoped lang="scss">
	.tab-title {
		font-size: 16px;
		font-weight: bold;
		border-left: 4px solid #0D9AFF;
		font-family: PingFangSC-Medium;
		padding-left: 10px;
		margin-bottom: 20px;
	}
	.line{
		text-align: center;
	}
	table td{
		border:1px solid #c6c6c6;
	}
</style>